// page/person/focusme/focusme.js
var config = require('../../config.js');
var loadNotice = require('loadNotice.js');
var app = getApp();
var page = 0;
var size = 10;
var tab_page = {};
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    lastLoadTime: 0,
     windowHeight: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var data = {
      type: 'ANNOUNCEMENT',
      appScope: 'G',
      page: page,
      size: size
    }
    loadNotice.load_list(data, page, tab_page, that);
    wx.getSystemInfo({
      success: function (res) {
        //赋值
        that.setData({
          windowHeight: res.windowHeight - 10
        });
      }
    });  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];  //上一个页面

    prevPage.setData({
      noticeId: 0
    });
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: config.shareDes,
      path: '/pages/index/index',
      imageUrl: '../images/sharepic_1.jpg'
    }
    // return {
    //   title: config.shareName,
    //   desc: config.shareDes,
    //   path: '/pages/notice/notice'
    // }
  }, loadMore: function () {//加载更多
    var that = this;
    var currentPage = tab_page.page+1;//pageSize;
    if (currentPage < tab_page.pageSize) {

      var curTime = new Date().getTime();
      //上一次加载的时间
      var lastTime = this.data.lastLoadTime;
      that.setData({
        lastLoadTime: curTime
      });
      if (curTime - lastTime < 300) {
        return;
      }
      wx.showLoading({
        title: '加载中···',
      });
      var data = {
        type: 'ANNOUNCEMENT',
        appScope: 'G',
        page: currentPage,
        size: size
      }
     
      loadNotice.load_page(data, currentPage, tab_page, that);
    }
    var timeout = setTimeout(function () {
      wx.hideLoading();
      clearTimeout(timeout);
    }, 500);
  }, refesh: function () {//刷新

  }, details:function(e){
    var id=e.currentTarget.dataset.id;
    if(id==0||id==null){
      return;
    }

    if(this.data.noticeId==id){
      return;
    }
    this.setData({
      noticeId:id
    });
    wx.navigateTo({
      url: 'details?id='+id,
    })
  }

})